﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;

namespace MReviewerClient.CustomConverters
{
    /// <summary>
    /// The converter is responsible for converting a rating to image
    /// </summary>
    public class Rating2ImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                var str = string.Empty;
                var point = double.Parse(value.ToString());

                if (point == 0)
                {
                    str = @"\Resources\rating_0.png";
                }
                else if (point <= 2)
                {
                    str = @"\Resources\rating_1.png";
                }
                else if (point <= 4)
                {
                    str = @"\Resources\rating_2.png";
                }
                else if (point <= 6)
                {
                    str = @"\Resources\rating_3.png";
                }
                else if (point <= 8)
                {
                    str = @"\Resources\rating_4.png";
                }
                else 
                {
                    str = @"\Resources\rating_5.png";
                }

                return str;
            }
            catch
            {
                return "0star.gif";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
